<?php
namespace org\GoApi;
use Exception;

class FamilyCtrl {
  public static function Read($GroupID) { // 读取
    $retn = [];
    try {
      $data = CallGameSrv('GroupRange/Read', ['GroupID' => $GroupID]);
      $data = json_decode($data, true);
      if (!empty($data['Data'][0])) {
        $retn = $data['Data'][0];
      }
    } catch (Exception $e) {
      //
    }
    return $retn;
  }
  public static function Remove($GroupID) { // 删除
    $data = CallGameSrv('GroupRange/Delete', ['GroupID' => $GroupID]);
    $data = json_decode($data, true);
    $data = $data['ErrorCode'];
    return $data; // 0=成功
  }
  public static function Page($page = 1, $size = 20) { // 分页
    $page = $page > 0 ? $page : 1;
    $size = $size > 0 ? $size : 20;
    $retn = [];
    try {
      $data = CallGameSrv('GroupRange/Page', ['page' => $page, 'size' => $size]);
      $retn = json_decode($data, true);
    } catch (Exception $e) {
      //
    }
    return $retn;
  }
  public static function Save($GroupID, $LimitMin, $LimitMax) {  // 添加/保存
    $data = CallGameSrv('GroupRange/Save', [
      'GroupID'   => $GroupID,
      'LimitMin'  => $LimitMin,
      'LimitMax'  => $LimitMax,
    ]);
    $data = json_decode($data, true);
    $data = $data['ErrorCode'];
    return $data;  // 0=成功
  }
  public static function Find($GroupID) {
    $retn = [];
    if (is_array($GroupID)) {
      $GroupID = implode(',', $GroupID);
    }
    try {
      $data = CallGameSrv('GroupRange/Find', ['GroupID' => $GroupID]);
      $retn = json_decode($data, true);
    } catch (Exception $e) {
      //
    }
    return $retn;
  }
}
